from django import forms
from django.contrib.auth.models import User
from django.contrib.localflavor.br.forms import BRPhoneNumberField
from django.core.mail import send_mail

__author__ = 'Wouker'

class userForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ('username','first_name','last_name','email','password')

    def clean_username(self):
        if User.objects.filter(
            username=self.cleaned_data['username'],
        ).count():
            raise forms.ValidationError('Ja existe um usuario com este e-mail')

        return self.cleaned_data['username']

class FormContact(forms.Form):
    nome = forms.CharField(max_length=50)
    email = forms.EmailField(label = ('E-mail'),required=False,widget=forms.TextInput(attrs={'placeholder': 'Email'}))
    mensagem = forms.Field(widget=forms.Textarea,)

    def enviar(self):
        titulo = 'Mensagem enviada pelo site'
        destino = 'credishop@gmail.com'
        texto = """
        Nome: %(nome)s
        E-mail: %(email)s
        Mensagem: %(mensagem)s
        """ % self.cleaned_data

        send_mail(
            subject=titulo,
            message=texto,
            from_email=destino,
            recipient_list=[destino],
        )